package org.easy.minimaxi;


import org.easy.core.util.ObjectUtil;

/**
 * 通用方法封装工具类
 */
public class MinimaxiTemplate {

    private final MinimaxiClient minimaxiClient;


    public MinimaxiTemplate(MinimaxiClient client) {
        this.minimaxiClient = client;
    }

    public String imgToVideo(String fileUrl, String prompt) {
        String taskId = minimaxiClient.commit(fileUrl, prompt);
        return getAllResult(taskId);
    }

    private String getAllResult(String generateUuid) {
        String query = minimaxiClient.query(generateUuid);

        while (ObjectUtil.isEmpty(query)) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            query = minimaxiClient.query(generateUuid);
        }
        return query;
    }

}